-
Notifications
You must be signed in to change notification settings - Fork 14
CLOUDP-285964: Adds IPA rule 104 - Resource has get #301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
tools/spectral/ipa/rulesets/functions/utils/resourceEvaluation.js
Outdated
Show resolved
Hide resolved
}, | ||
]; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: What if it is not a singleton and standard resource?(The equivalent of /custom
in the tests). Don't we check for get
method at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For /custom
in the tests, we do check these as well. It's basically a standard resource with extra custom methods, in these cases, we ignore the custom methods (since they can be post or get) and only check the children (/custom/{exampleId}
in the tests)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently we have no resources that fall into neither standard nor singleton (with the checks currently implemented)
import testRule from './__helpers__/testRule'; | ||
import { DiagnosticSeverity } from '@stoplight/types'; | ||
|
||
testRule('xgen-IPA-104-resource-has-GET', [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a case with nested resource?
/groups/{groupId}/clusters
? and a singleton like /groups/{groupId}/settings
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we unit test these, and if not can we add some examples to things like isSingletonResource
or isStandardResource
it's a bit hard to follow the intention of the method and some examples either in text or as actual tests would be of great help in the future if we need to debug or change those functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, makes sense, I'll add unit tests for them as well (getResourcePaths, isStandardResource and isSingletonResource as they are probably the tricky ones)
const customChildMethodPattern = new RegExp(`^${parent}/{[a-zA-Z]+}:+[a-zA-Z]+$`); | ||
const customMethodPattern = new RegExp(`^${parent}:+[a-zA-Z]+$`); | ||
return allPaths.filter( | ||
(p) => parent === p || childPathPattern.test(p) || customMethodPattern.test(p) || customChildMethodPattern.test(p) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The added tests revealed that we were missing a custom case, as it can be either /path/{id}:method
or /path:method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, exciting! 🚀
Proposed changes
npm run test
npm run ipa-validation
Example output:
Jira ticket: CLOUDP-285964
Follow up